﻿using System.Collections;
using UnityEngine.UI;
using UnityEngine;

public class EnemyHealth : MonoBehaviour {

    public int hp = 100;
    private int hpTotal;

    public Slider m_hpSlider;


	void Start ()
    {
        hpTotal = hp;
	}

    void TakeDamage()
    {
        if (hp <= 0) return;

        hp -= Random.Range(10, 20);
        m_hpSlider.value = (float)hp / hpTotal;

        if (hp<=0)//受到伤害之后，血量小于0，死亡
        {
            GameObject.Destroy(this.gameObject);
            //死亡代码
        }
    }
}
